// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class COMMAND_RESPONSE_EAR_U08 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("4 ECD",4)]
  	    [HL7Field(HL7Version.v24, 4, HL7Repeat.False, HL7Required.True,"ECD")]
	    public ECD ECD {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("6 SAC",6)]
  	    [HL7Field(HL7Version.v24, 6, HL7Repeat.False, HL7Required.False,"SAC")]
	    public SAC SAC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("8 ECR",8)]
  	    [HL7Field(HL7Version.v24, 8, HL7Repeat.False, HL7Required.True,"ECR")]
	    public ECR ECR {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			ECD = PopSegmentParseAndCheckRequired<ECD>(availableData, options, "ECD");
			SAC = PopSegmentParseAndCheckRequired<SAC>(availableData, options, "SAC");
			ECR = PopSegmentParseAndCheckRequired<ECR>(availableData, options, "ECR");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isECD = availableData.StartsWith("ECD", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ECD", options.Version) || isECD) {
				return isECD;
			}
			bool isSAC = availableData.StartsWith("SAC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("SAC", options.Version) || isSAC) {
				return isSAC;
			}
			bool isECR = availableData.StartsWith("ECR", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ECR", options.Version) || isECR) {
				return isECR;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "COMMAND_RESPONSE";
			}
        }

        static COMMAND_RESPONSE_EAR_U08() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(COMMAND_RESPONSE_EAR_U08));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (ECD != null) {
			string segmentValue = ECD.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (SAC != null) {
			string segmentValue = SAC.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (ECR != null) {
			string segmentValue = ECR.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

